// main.cpp
//

#include "PursuitInput.h"

// Lokale Funktion - nicht im Header
BOOL CALLBACK EnumDevicesCallback(LPCDIDEVICEINSTANCE pDeviceInstance,
								  void* pRef);

LPDIRECTINPUT8 PI_DInput;
HINSTANCE hDLL;

int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pReserved)
{
	hDLL = hInstance;

	return TRUE;
}

PINPUT_API PDRESULT PIInit(HWND hWnd, PCSettings settings)
{
	HRESULT hr = DirectInput8Create(hDLL, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)(&PI_DInput), NULL);
	if (FAILED(hr))
	{
		PCErrorDX(hr, "Konnte DirectInput nicht initialsieren!");
		return PDERROR_DINPUTINIT;
	}
	
	PI_DInput->EnumDevices(DI8DEVCLASS_ALL, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY);
	 
	PDRESULT keyinit = PIInitKeyboard(hWnd);
	if (PDFAILED(keyinit))
		return keyinit;

	return PD_OK;
}

BOOL CALLBACK EnumDevicesCallback(LPCDIDEVICEINSTANCE pDeviceInstance,
								  void* pRef)
{
	return DIENUM_CONTINUE;
}

PINPUT_API void PIRelease(void)
{
	if (PI_DInput != NULL) PI_DInput->Release();
}